package com.study.observermode.publisher;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEvent;
import org.springframework.stereotype.Component;

/**
 * @ClassName: MyPublisher
 * @Description: spring中用于发布事件
 * @Details: 
 * @Author: 郑港旭
 * @Create: 2021-11-16 16:58
 **/
public class MyPublisher implements ApplicationContextAware {
    private ApplicationContext context;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.context = applicationContext;
    }

    public void publishEvent(ApplicationEvent event){
        System.out.println("publish event");
        context.publishEvent(event);
    }
}
